package com.example.maple.ccsclient.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.DashPathEffect;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PathEffect;
import android.util.AttributeSet;
import android.view.View;

/**
 * Created by maple on 2016/8/15.
 */
public class LineView extends View{


	//默认绘制红色线条每个四个像素绘制
	private static final int RED_LINE_LENGTH = 4;
	//View的宽度，也就是我们绘制红色的宽度
	private static int viewWidth;
	//绘制的距离
	private  static int viewHeight;

	//绘制画笔
	Paint mPaint;
	Path mPath;
	public LineView(Context context) {
		super(context);
		init();
	}

	public LineView(Context context, AttributeSet attrs) {
		super(context, attrs);
		init();
	}

	public LineView(Context context, AttributeSet attrs, int defStyleAttr) {
		super(context, attrs, defStyleAttr);
		init();
	}

	private void init() {
		mPaint = new Paint();
		mPaint.setStyle(Paint.Style.STROKE);
		mPaint.setColor(Color.RED);
		mPath = new Path();



	}
	@Override
	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
		super.onMeasure(widthMeasureSpec, heightMeasureSpec);
	}

	/*
		*
		* 绘制断断续续的线条
		* */
	@Override
	protected void onDraw(Canvas canvas) {
		mPath.moveTo(0, 0);
		mPath.lineTo(getMeasuredWidth(),getMeasuredHeight());
		PathEffect effects = new DashPathEffect(new float[]{5,5,5,5},1);
		mPaint.setPathEffect(effects);
		canvas.drawPath(mPath, mPaint);
	}
}
